package com.dayuanit.dy14.enter.dy14enter1024.task;

import com.dayuanit.dy14.enter.dy14enter1024.service.EmailService;
import com.dayuanit.dy14.enter.dy14enter1024.service.GroupService;
import com.dayuanit.dy14.enter.dy14enter1024.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class GroupTask extends BaseTask {

    private static volatile boolean groupFlag = false;//可见性的问题

    @Autowired
    private EmailService emailService;

    @Value("${deadline.time}")
    private String deadTime;

    @Autowired
    private GroupService groupService;

    @Scheduled(cron = "0/10 * * * * *")
    @Override
    public void process() {
//        Date groupDate = DateUtils.string2Date(deadTime);
//        if (!new Date().after(groupDate)) {
//            System.out.println("分组时间没有到...");
//            return;
//        }
//
        if (groupFlag) {
            System.out.println("已分组");
            return;
        }
//
//        System.out.println("开始分组...");
//        //TOOD 分组
//        groupService.groupUser();
//
//        groupFlag = true;
//        System.out.println("结束分组...");

        System.out.println("开始批量发送email...");
        //TODO 批量发邮件
        emailService.batchSendEmail3();

        groupFlag = true;
    }
}
